package com.ygqh.baby.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.mapper.YgReturnLogMapper;
import com.ygqh.baby.po.YgReturnLog;
import com.ygqh.baby.po.YgReturnLogExample;
import com.ygqh.baby.service.YgReturnLogService;

@Service
public class YgReturnLogServiceImpl implements YgReturnLogService {

	@Autowired
	private YgReturnLogMapper ygReturnLogMapper;

	@Override
	public List<YgReturnLog> find() {
		YgReturnLogExample example = new YgReturnLogExample();
		example.createCriteria();
		return ygReturnLogMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgReturnLogExample example = new YgReturnLogExample();
		example.createCriteria();
		return ygReturnLogMapper.countByExample(example);
	}

	@Override
	public YgReturnLog findById(Long id) {
		return ygReturnLogMapper.selectByPrimaryKey(id);
	}

	@Override
	public int save(YgReturnLog ygReturnLog) {
		return ygReturnLogMapper.insertSelective(ygReturnLog);
	}

	@Override
	public int update(YgReturnLog ygReturnLog) {
		return ygReturnLogMapper.updateByPrimaryKeySelective(ygReturnLog);
	}

	@Override
	public ResultSet<YgReturnLog> search(QueryInfo queryInfo, String q) {
		List<YgReturnLog> list = ygReturnLogMapper.selectSuper(queryInfo, q);
		int count = ygReturnLogMapper.countSuper(q);
		ResultSet<YgReturnLog> resultSet = new ResultSet<YgReturnLog>(count, list);
		return resultSet;
	}

	@Override
	public int saveOrUpdate(YgReturnLog ygReturnLog) {
		int r = 0;
		if (ygReturnLog.getId() != null) {
			r = this.update(ygReturnLog);
		} else {
			r = this.save(ygReturnLog);
		}
		return r;
	}

	@Override
	public int addReturnLog(String returnCode, Long orderId, String operation, String createBy, String remark) {
		YgReturnLog ygReturnLog = new YgReturnLog(returnCode, orderId, operation, createBy, remark);
		return this.save(ygReturnLog);
	}

}
